﻿@{
    ViewBag.Title = "Danh sách sản phẩm";
    Layout = "~/Views/Shared/Admin/_AdminLayout.cshtml";
}
@using PagedList.Mvc;
@using PagedList;
<div id="content" class="span10">
    <!-- content starts -->
    <div>
        <ul class="breadcrumb">
            <li>
                <a href="#">Home</a> <span class="divider">/</span>
            </li>
            <li>
                <a href="#">Danh sách sản phẩm</a>
            </li>
        </ul>
    </div>
    <div class="row-fluid sortable">
        <div class="box span12">
            <div class="box-content">
                <div class="row-fluid">
                    <div class="span12 form-inline">
                        @using (Html.BeginForm("DanhSach", "AdminSanPham", FormMethod.Get))
                        {
                            <div id="search-box" style="text-align: left">
                                Tên sản phẩm
                                <input type="text" name="SearchString" class="input" value="@ViewBag.CurrentFilter" placeholder="Tên sản phẩm..."/>
                                Danh mục
                        @Html.DropDownList("IdDanhMuc", null, new { id = "DanhMuc" })
                                Thương hiệu
                        @Html.DropDownList("IdthuongHieu", "Tất cả")
                                <button class="btn btn-small" type="submit"><i class="icon-search"></i>Tìm kiếm</button>
                            </div>
                        }
                    </div>

                </div>
                <div class="row-fluid">
                    <div style="float:left;">
                        <a href="~/AdminSanPham/ThemMoi" class="btn btn-large btn-success">
                            <i class="icon-plus icon-white"></i>
                            Thêm mới
                        </a>
                    </div>
                    <div style="float:right;margin-right:20px;">
                        Hiển thị 
                       <select id="HienThi" style="width: 100px;">
                           <option value="5" @if (ViewBag.HienThi == 10)
                                             { @:selected="selected" 
                               }>5</option>
                           <option value="10" @if (ViewBag.HienThi == 10)
                                              { @:selected="selected" 
                               }>10</option>
                           <option value="15" @if (ViewBag.HienThi == 15)
                                              { @:selected="selected" 
                               }>15</option>
                           <option value="20" @if (ViewBag.HienThi == 20)
                                              { @:selected="selected" 
                               }>20</option>
                           <option value="50" @if (ViewBag.HienThi == 50)
                                              { @:selected="selected" 
                               }>50</option>
                       </select>
                        Sắp xếp
                       <select id="SapXep" style="width: 100px;">
                           <option value="0" @if (ViewBag.SapXep == 0)
                                             { @:selected="selected" 
                               }>Mặc định</option>
                           <option value="1" @if (ViewBag.SapXep == 1)
                                             { @:selected="selected" 
                               }>Giá tăng dần</option>
                           <option value="2" @if (ViewBag.SapXep == 2)
                                             { @:selected="selected" 
                               }>Giá giảm dần</option>
                           <option value="3" @if (ViewBag.SapXep == 3)
                                             { @:selected="selected" 
                               }>Tên a đến z</option>
                           <option value="4" @if (ViewBag.SapXep == 4)
                                             { @:selected="selected" 
                               }>Tên z về a</option>
                       </select>
                        <script>
                            $("#HienThi").change(function () {
                                var hienthi = $(this).val();
                                window.location.href = 'http://' + window.location.host + '/AdminSanPham/DanhSach/?HienThi=' + hienthi + '&SapXep=@ViewBag.SapXep' + '&currentFilter=@ViewBag.CurrentFilter' + '&IdDanhMuc=@ViewBag.DanhMuc' + '&IdThuongHieu=@ViewBag.ThuongHieu';

                            });
                            $("#SapXep").change(function () {
                                var sapxep = $(this).val();
                                window.location.href = 'http://' + window.location.host + '/AdminSanPham/DanhSach/?SapXep=' + sapxep + '&HienThi=' + @ViewBag.HienThi + '&currentFilter=@ViewBag.CurrentFilter' + '&IdDanhMuc=@ViewBag.DanhMuc'+'&IdThuongHieu=@ViewBag.ThuongHieu';

                            });
                        </script>
                    </div>

                </div>
                <div style="height:10px;"></div>
                <table class="table table-striped table-bordered bootstrap-datatable datatable">
                    <thead>
                        <tr>
                            <th>ID</th>
                            <th>Mã sản phẩm</th>
                            <th>Ảnh</th>
                            <th>Tên sản phẩm</th>
                            <th>Giá gốc</th>
                            <th>Giá khuyến mãi</th>
                            <th>Số lượng còn</th>
                            <th>Active</th>
                            <th></th>
                        </tr>
                    </thead>
                    <tbody>
                        @{PagedList<BabyToys.Models.SanPham> sanphams = ViewBag.onePageOfProduct;}

                        @foreach (var sanpham in sanphams)
                        {
                            <tr>
                                <td class="item_float">@sanpham.IdSanPham</td>
                                <td class="item_float">@sanpham.MaSP</td>
                                <td><img src="~/Content/Images/SanPham/@sanpham.Thumbnail" style="width:40px;height:40px;"/></td>
                                <td class="item_float">@sanpham.TenSP</td>
                                <td class="item_float">@sanpham.Gia</td>
                                <td class="item_float">@sanpham.GiaKhuyenMai()</td>
                                <td class="item_float">@sanpham.SoLuong()</td>
                                <td class="item_float">
                                    @{int idd = @sanpham.IdSanPham;}
                                    
                                    <input id="@Html.Raw("chkHienThi" + sanpham.IdSanPham)" type="checkbox" onclick="CapNhatHienThi(@sanpham.IdSanPham);" 
                                        @if (@sanpham.HienThi == true){@:checked="checked"
                                        }
                                        @Html.Raw(ViewBag.Xoa == true ? "" : "disabled=\"disabled\"")
                                        />
                                    <script>
                                        function CapNhatHienThi(id) {
                                            var ten = '#chkHienThi' + id;
                                            var hienthi = $(ten).is(':checked') ? true : false;
                                            //alert("a:"+x+"b:"+id);
                                            var x = confirm("Bạn có chắc muốn cập nhật sản phẩm này?");
                                            if (x == true) {
                                                //var ten = '#IsActive' + id;
                                                var id = id;
                                                $.post("/AdminSanPham/CapNhatHienThi/", { "id": id, "hienthi": hienthi },
                                                    function (data) {
                                                        alert("Cập Nhật Thành Công");
                                                        window.location.reload();
                                                    });
                                            }
                                            else {
                                                window.location.reload();
                                            }
                                        }
                                    </script>
                                </td>
                                <td class="td-actions">
                                    <div class="hidden-phone visible-desktop action-buttons">
                                        <a href="~/san-pham/@sanpham.IdSanPham/" class="btn btn-inverse">
                                        <i class="icon-zoom-in icon-white"></i>
                                            Xem                                            
									    </a>

                                        <a href="~/AdminSanPham/Sua/@sanpham.IdSanPham" class="btn btn-info">
                                            <i class="icon-edit icon-white"></i>
                                            Sửa
                                        </a>
                                        @{int id = @sanpham.IdSanPham;
                                          string name = @sanpham.TenSP;
                                        }
                                    </div>
                                </td>
                            </tr>
                        }
                    </tbody>
                </table>
                <div class="pagination pagination-centered">
                    @Html.PagedListPager((IPagedList)ViewBag.onePageOfProduct, page => Url.Action("DanhSach", new { page, HienThi = @ViewBag.HienThi, SapXep = @ViewBag.SapXep, currentFilter = @ViewBag.CurrentFilter, IdDanhMuc = @ViewBag.DanhMuc, IdThuongHieu = @ViewBag.ThuongHieu }), PagedListRenderOptions.OnlyShowFivePagesAtATime)
                </div>
            </div>
        </div>
    </div>
</div>

